// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.chimi.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.chimi.controller.request.QueryBarPresentFlowReq;
import com.liuxinlong.modules.chimi.controller.request.UpdateBarPresentFlowReq;
import com.liuxinlong.modules.chimi.service.BarPresentFlowService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.BarPresentFlow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 论坛礼品流水控制层
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022-07-28
 */
@RestController
@RequestMapping("/present-flow")
public class BarPresentFlowController {

	@Autowired
	private BarPresentFlowService barPresentFlowService;

	/**
	 * 分页查询礼品流水信息
	 * 
	 * @param req 请求信息
	 * @return 礼品流水信息列表
	 */
	@PostMapping("page")
//	@LogAnnotation(value ="分页查询",business = LogBusinessConstants.BAR_PRESENT_FLOW,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp pagePresentFlow(@RequestBody QueryBarPresentFlowReq req) {
		Map<String,Object> queryParam = new HashMap<>();
		queryParam.put("startNum",req.getStartNum());
		queryParam.put("pageSize",req.getPageSize());
		queryParam.put("presentId",req.getPresentId());
		queryParam.put("luckId",req.getLuckId());
		queryParam.put("userId",req.getUserId());
		queryParam.put("status",req.getStatus());
		List<Map<String,Object>> dataList = barPresentFlowService.pagePresentFlow(queryParam);
		int total = barPresentFlowService.getPresentFlowCount(queryParam);
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setTotalNum(total);
		resp.setRetMessage("分页查询礼品流水信息成功");
		return resp;
	}

	/**
	 * 新增中奖记录
	 *
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("add")
	@LogAnnotation(value ="新增中奖记录",business = LogBusinessConstants.BAR_PRESENT_FLOW,operateType = LogOperateConstants.OPERATE_ADD)
	public BaseResp addPresentFlow(@RequestBody UpdateBarPresentFlowReq req) {
		BarPresentFlow barPresentFlow = new BarPresentFlow();
		barPresentFlow.setLuckId(req.getLuckId());
		barPresentFlow.setPresentId(req.getPresentId());
		barPresentFlow.setUserId(req.getUserId());
		barPresentFlow.setStatus(req.getStatus());
		barPresentFlow.setOperateTime(req.getOperateTime());
		barPresentFlowService.addPresentFlow(barPresentFlow);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("新增中奖记录成功");
		return resp;
	}

	/**
	 * 修改中奖记录
	 *
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("update")
	@LogAnnotation(value ="修改中奖记录",business = LogBusinessConstants.BAR_PRESENT_FLOW,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updatePresentFlow(@RequestBody UpdateBarPresentFlowReq req) {
		BarPresentFlow barPresentFlow = new BarPresentFlow();
		barPresentFlow.setId(req.getId());
		barPresentFlow.setLuckId(req.getLuckId());
		barPresentFlow.setPresentId(req.getPresentId());
		barPresentFlow.setUserId(req.getUserId());
		barPresentFlow.setStatus(req.getStatus());
		barPresentFlow.setOperateTime(req.getOperateTime());
		barPresentFlowService.updatePresentFlow(barPresentFlow);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改中奖记录成功");
		return resp;
	}

	/**
	 * 修改礼品发放状态
	 *
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("status/update")
	@LogAnnotation(value ="修改礼品发放状态",business = LogBusinessConstants.BAR_PRESENT_FLOW,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updatePresentFlowStatus(@RequestBody BaseDeleteReq req) {
		barPresentFlowService.updatePresentFlowStatus(req.getId());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改礼品发放状态成功");
		return resp;
	}


	/**
	 * 导出中奖记录信息
	 *
	 * @param req 请求信息
	 * @return 导出数据
	 */
	@PostMapping("export")
	@LogAnnotation(value ="导出中奖记录信息",business = LogBusinessConstants.BAR_PRESENT_FLOW,operateType = LogOperateConstants.OPERATE_EXPORT)
	public void exportPresentFlow(@RequestBody BaseDeleteReq req, HttpServletResponse response) {
		barPresentFlowService.exportPresentFlow(req.getId(),response);
	}

}
